package pl.streamsoft.currencyApp.App;

import pl.streamsoft.currencyApp.dao.CountryDAO;
import pl.streamsoft.currencyApp.dao.CurrencyDAO;
import pl.streamsoft.currencyApp.model.Country;

public class CurrencyAppTest {

	/**
	 * @param args
	 * pawel000000000000
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		/*try {
			CurrencyService curService =
					new CurrencyService(new InputStreamReader(new URL("http://nbp.pl/kursy/xml/LastA.xml").openStream(), "ISO-8859-2"), new XMLCurrencyParser());
			
			List<Currency> lista = curService.getListOfCurrencies();
			
			//toooo
			List<Currency> lista2 = curService.getListOfCurrenciesFromDate("130715",'a');
			
			for(Currency el: lista){
				System.out.println("Name of the currency: "+el.getName()+ ", code: "+el.getCurrencyCode()+ ", converter: "+ el.getConverter()+ ", average rate: "+el.getAverageRate());
			}
			
			Country countryPoland = new Country();
			countryPoland.setName("POLAND");
			List<Currency> listOfPolandCurrencies = new ArrayList<Currency>();
			listOfPolandCurrencies.add(curService.getCurrencyByName("bat (Tajlandia)"));
			listOfPolandCurrencies.add(curService.getCurrencyByCode("USD"));
			for(Currency el: listOfPolandCurrencies){
				countryPoland.getCurrencyList().add(el);
			}
			
			Country countryUkraine = new Country();
			countryUkraine.setName("UKRAINE");
			List<Currency> listOfUkraineCurrencies = new ArrayList<Currency>();
			listOfUkraineCurrencies.add(curService.getCurrencyByName("dolar ameryka�ski"));
			listOfUkraineCurrencies.add(curService.getCurrencyByCode("HKD"));
			for(Currency el: listOfUkraineCurrencies){
				countryUkraine.getCurrencyList().add(el);
			}
			
			List<Country> listOfCountries = new ArrayList<Country>();
			listOfCountries.add(countryPoland);
			listOfCountries.add(countryUkraine);
			
			ICountryService countryService = new CountryService(listOfCountries);
			Country countryFrance = new Country();
			countryFrance.setName("FRANCE");
			List<Currency> listOfFranceCurrency = new ArrayList<Currency>();
			listOfFranceCurrency.add(curService.getCurrencyByName("funt szterling"));
			listOfFranceCurrency.add(curService.getCurrencyByCode("EUR"));
			for(Currency el: listOfFranceCurrency){
				countryFrance.getCurrencyList().add(el);
			}
			countryService.addCountryToList(countryFrance);
			
			System.out.println("--------------------------------------------------------------------------------------------------");
			
			Country countryP = countryService.getCountryByName("POLAND");
			System.out.println("POLISH CURRENCIES ARE:");
			for(Currency el: countryP.getCurrencyList()){
				System.out.println("Name of the currency: "+el.getName()+ ", code: "+el.getCurrencyCode()+ ", converter: "+ el.getConverter()+ ", average rate: "+el.getAverageRate());
			}
			
			System.out.println("--------------------------------------------------------------------------------------------------");
			
			List<Country> listOfC = countryService.getListOfCountries();
			for(Country el: listOfC){
				System.out.println("Name of country is: "+el.getName());
				for(Currency elem: el.getCurrencyList()){
					System.out.println("Name of the currency: "+elem.getName()+ ", code: "+elem.getCurrencyCode()+ ", converter: "+ elem.getConverter()+ ", average rate: "+elem.getAverageRate());
				}
			}
		} 
		catch (Exception e) {
			e.printStackTrace();
		}*/
		
		/*DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date date2 = formatter.parse("2013-07-18");*/
		
		CountryDAO co = new CountryDAO();
		CurrencyDAO curr = new CurrencyDAO();
		
		/*
		Country country = co.getCountryFromDB("Ukraine");
		Currency currency = new Currency("hrywnia",1,"HRN",new BigDecimal("0.4222"), new Date());
		Currency currency2 = new Currency("hrywnia",1,"HRN",new BigDecimal("0.4222"), new Date());
		country.getCurrencyList().add(currency);
		country.getCurrencyList().add(currency2);
		co.insertCountryIntoDB(country);*/
		
		Country country2 = co.getCountryFromDB("Ukraine");
		System.out.println(country2.getCurrencyList().size());
		
		Country country3 = co.getCountryFromDB("Ukraine");
		System.out.println(country3.getCurrencyList().size());
		
		/*List<Currency> list = new ArrayList<Currency>();
		Currency currency = new Currency("hrywnia",1,"HRN",new BigDecimal("0.4222"), new Date());
		Currency currency2 = new Currency("hrywnia",1,"HRN",new BigDecimal("0.4222"), new Date());
		list.add(currency);
		list.add(currency2);
		
		Set<Currency> setOFCurrencies = new HashSet<Currency>();
		setOFCurrencies.addAll(list);
		for(Currency el:setOFCurrencies){
			System.out.println(el.getName()+" "+el.getAverageRate());
		}
		
		list.clear();
		list.addAll(setOFCurrencies);
		
		System.out.println(list.size());*/
		
	/*	curr.deleteCurrencyFromCountry("Ukraine", new Currency("hrywnia",1,"HRN",new BigDecimal("0.4222"), new Date()));
		
		Country countryU = co.getCountryFromDB("Ukraine");
		System.out.println(countryU.getCurrencyList().size());*/
		
		/*AppService service = new AppService();
		
		

		Country country1 = service.getCountry("Ukraine");
		
		Country country2 = service.getCountry("Ukraine");*/
		
/*		AppService service = new AppService();
		for(Currency el: service.getAllCurrenciesOfCountry("Ukraine")){
			System.out.println(el.getName());
		}*/
		/*List<Currency> list = service.getAllCurrenciesFromDateByType(new Date(), 'a');
		for(Currency curr: list){
			System.out.println(curr.getName()+"\n");
		}*/
		/*CurrencyService curService = null;
		List<Currency> lista = 	null;
		try {
			curService = new CurrencyService(new InputStreamReader(new URL("http://nbp.pl/kursy/xml/LastA.xml").openStream(), "ISO-8859-2"), new XMLCurrencyParser());
			lista = curService.getListOfCurrencies();
			
			for(Currency el: lista){
				System.out.println(el.getName() + " "+el.getAverageRate());
			}
		} catch (Exception e){
			e.printStackTrace();
		}*/
		/*String date = new Date().toLocaleString().substring(0, 10);
		date = date.substring(2, date.length());
		date = date.replace('-', ' ');
		date = date.replaceAll("\\s","");
		System.out.println(date);*/
		
		/*SessionFactory sf = new Configuration().configure().buildSessionFactory();
		Session se = sf.openSession();
		se.beginTransaction();
		
		se.save(new Currency("dolar amerykański",1, "USD", new BigDecimal("3.21"),"130202"));
		
		se.getTransaction().commit();
		se.close();*/
	}

}
